<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>用户列表 - BsAdmin后台模板 - 经典版演示</title>

</head>
<body>
<div id="app" class="d-flex">
    <jsp:include page="/left.jsp"></jsp:include>
    <main>
        <header>
            <a href="http://www.qadmin.net" target="_blank">网站首页</a>
            <div class="dropdown float-right">
                <button class="btn  btn-sm  dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown"
                        aria-haspopup="true" aria-expanded="false">
                    <svg width="20" height="1em" viewBox="0 0 16 16" class="bi bi-emoji-smile-fill rounded-circle"
                         fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                        <path fill-rule="evenodd"
                              d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16zM7 6.5C7 7.328 6.552 8 6 8s-1-.672-1-1.5S5.448 5 6 5s1 .672 1 1.5zM4.285 9.567a.5.5 0 0 1 .683.183A3.498 3.498 0 0 0 8 11.5a3.498 3.498 0 0 0 3.032-1.75.5.5 0 1 1 .866.5A4.498 4.498 0 0 1 8 12.5a4.498 4.498 0 0 1-3.898-2.25.5.5 0 0 1 .183-.683zM10 8c.552 0 1-.672 1-1.5S10.552 5 10 5s-1 .672-1 1.5S9.448 8 10 8z"/>
                    </svg>
                    <!--可以使用图片,大小20,class='rounded-circle'-->
                    BsAdmin
                </button>
                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu2">
                    <a class="dropdown-item" href="repwd.html">修改密码</a>
                    <a class="dropdown-item" href="out.html">退出登录</a>
                </div>
            </div>
        </header>
        <div id="body">
            <main>
                <div class="main">
                    <div class="search">
                        <form class="form-inline float-left" action="" method="get">
                            <div class="form-group">
                                <input type="text" id="key" name="key" value="" class="form-control"
                                       placeholder="手机号/昵称/UID">
                            </div>
                            <button type="button" id="searchBtn" class="btn btn-primary"><i class="iconfont"></i>搜索
                            </button>
                        </form>
                  <%--      <a class="btn btn-primary float-right" onclick="loadColumn()" href="#"><i class="iconfont"></i>柱状</a>
                        <a class="btn btn-primary float-right" onclick="loadPie()" href="#"><i class="iconfont"></i>饼图</a>
                        <a class="btn btn-primary float-right" onclick="loadLine()" href="#"><i class="iconfont"></i>折线</a>--%>
                    </div>
                    <div class="table-box">
                        <table id="tb1" class="table">
                        </table>
                    </div>

                    <div id="container" style="height: 100%" class="page">

                    </div>
                </div>
            </main>
        </div>
    </main>
</div>
</body>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/echarts.min.js"></script>
<script type="text/javascript">

    function loadColumn() {
        var myChart = echarts.init(document.getElementById('container'));
        // 显示标题，图例和空的坐标轴
        myChart.setOption({
            title: {
                text: '异步数据加载示例1'
            },
            tooltip: {},
            legend: {
                data: ['销量']
            },
            xAxis: {
                data: []
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: []
            }]
        });

        myChart.showLoading(); //数据加载完之前先显示一段简单的loading动画

        var names = []; //类别数组（实际用来盛放X轴坐标值）
        var nums = []; //销量数组（实际用来盛放Y坐标值）

        $.ajax({
            type: "get",
            async: true, //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
            url: "${pageContext.request.contextPath}/echarts/ColunmServlet", //
            data: {},
            dataType: "json", //返回数据形式为json
            success: function (result) {
                //请求成功时执行该函数内容，result即为服务器返回的json对象
                console.log(result);
                if (result) {
                    for (var i = 0; i < result.length; i++) {
                        names.push(result[i].name); //挨个取出类别并填入类别数组
                    }
                    for (var i = 0; i < result.length; i++) {
                        nums.push(result[i].value); //挨个取出销量并填入销量数组
                    }
                    myChart.hideLoading(); //隐藏加载动画
                    myChart.setOption({ //加载数据图表
                        xAxis: {
                            data: names
                        },
                        series: [{
                            // 根据名字对应到相应的系列
                            name: '销量',
                            data: nums,
                            //设置颜色
                            itemStyle: {
                                normal: {
                                    color: 'red',
                                }
                            }
                        }]
                    });

                }
            },
            error: function (errorMsg) {
                //请求失败时执行该函数
                alert("图表请求数据失败!");
                myChart.hideLoading();
            }
        });
    }

    loadColumn();

</script>

</html>
